﻿using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.App.UI.Seller
{
    /// <summary>
    /// SellerInfo.xaml 的交互逻辑
    /// </summary>
    public partial class SellerInfoUserControl : UserControl, IPlugin
    {
        private SellerService sellerService = ServiceContainer.GetService<SellerService>();

        public SellerInfoUserControl()
        {
            InitializeComponent();
        }

        public string Title
        {
            get { return "卖家信息"; }
        }

        public Control UIControl
        {
            get { return this; }
        }

        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            this.pbBar.Parameters.Clear();
            int id = 0;
            int.TryParse(this.tbId.Text.Trim(), out id);
            this.pbBar.Parameters.Add("id", id);
            this.pbBar.Parameters.Add("name", this.tbName.Text.Trim());
            this.pbBar.Parameters.Add("mail", this.tbMail.Text.Trim());
            this.pbBar.Parameters.Add("phone", this.tbPhone.Text.Trim());
            this.pbBar.Parameters.Add("startCreateTime", (this.tbRegisterStart.SelectedDate == null ? DateTime.MinValue : this.tbRegisterStart.SelectedDate.Value).Date);
            this.pbBar.Parameters.Add("endCreateTime", (this.tbRegisterEnd.SelectedDate == null ? DateTime.MinValue : this.tbRegisterEnd.SelectedDate.Value).Date.AddDays(1));
            this.pbBar.StartPage();
        }

        private void pbBar_PageChanging(object sender, PageBar.PageChangeEventArgs e)
        {
            var item = this.sellerService.GetByAll(e.GetParameter<int>("id"), e.GetParameter<string>("name"), e.GetParameter<string>("phone"), e.GetParameter<string>("mail"),"", e.GetParameter<DateTime>("startCreateTime"), e.GetParameter<DateTime>("endCreateTime"), e.CurrentPage - 1, e.PageSize);
            this.dgvSeller.ItemsSource = item.Datas;
            this.pbBar.Total = item.Total;
            this.pbBar.CurrentCount = item.Datas.Count;
        }
    }
}
